import React, { Component } from 'react'
import moment from 'moment'

export default class Clock extends Component {
  state={
    strTime:moment().format('YYYY-MM-DD HH:mm:ss')
  }
  render() {
    return (
      <div>
        <div style={{width: 200, padding: 20, border: 'solid 1px #abc'}}>
          {this.state.strTime}
        </div>
      </div>
    )
  }

  componentDidMount(){
    this.timer=setInterval(()=>{
      // console.log(1);
      let str=moment().format('YYYY-MM-DD HH:mm:ss')
      this.setState({
        strTime:str
      })
    },1000)
  }
  componentWillUnmount(){
    clearInterval(this.timer)
  }
}
